from rest_framework import serializers
from .models import StockBasic, TradeDate, DailyData, DailyBasic, ThsPlate, ThsStockPlate


class StockBasicSerializer(serializers.ModelSerializer):
    """
    股票基本信息序列化器
    """
    class Meta:
        model = StockBasic
        fields = [
            'ts_code', 'symbol', 'name', 'area', 'industry', 'fullname',
            'enname', 'cnspell', 'market', 'exchange', 'curr_type',
            'list_status', 'list_date', 'delist_date', 'is_hs'
        ]


class TradeDateSerializer(serializers.ModelSerializer):
    """
    交易日历序列化器
    """
    class Meta:
        model = TradeDate
        fields = [
            'exchange', 'cal_date', 'is_open', 'pretrade_date'
        ]


class DailyDataSerializer(serializers.ModelSerializer):
    """
    日线行情序列化器
    """
    class Meta:
        model = DailyData
        fields = [
            'ts_code', 'trade_date', 'open', 'high', 'low', 'close',
            'pre_close', 'change', 'pct_chg', 'vol', 'amount'
        ]


class DailyBasicSerializer(serializers.ModelSerializer):
    """
    每日指标序列化器
    """
    class Meta:
        model = DailyBasic
        fields = [
            'ts_code', 'trade_date', 'close', 'turnover_rate', 'turnover_rate_f',
            'volume_ratio', 'pe', 'pe_ttm', 'pb', 'ps', 'ps_ttm', 'dv_ratio',
            'dv_ttm', 'total_share', 'float_share', 'free_share', 'total_mv',
            'circ_mv'
        ]


class ThsPlateSerializer(serializers.ModelSerializer):
    """
    同花顺板块序列化器
    """
    class Meta:
        model = ThsPlate
        fields = [
            'ts_code', 'name', 'type', 'exchange', 'list_date'
        ]


class ThsStockPlateSerializer(serializers.ModelSerializer):
    """
    股票所属板块关系序列化器
    """
    class Meta:
        model = ThsStockPlate
        fields = [
            'ts_code', 'plate_code', 'plate_name', 'plate_type',
            'in_date', 'out_date', 'is_new'
        ]